// pages/home/index.js
var util = require('../../utils/util.js');
Component({

  /**
   * 页面的初始数据
   */
  data: {
    home: [],
    noticeNum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  ready: function(options) {
    this.init();
    
  },

  methods: {
    init() {
      let that = this;
      util.http({
        url: 'api/miniwechat/index/index'
      }).then((data) => {
        data.theme.forEach((item, i) => {
          item.list_list.forEach((sitem, j) => {
            if (j >= 3) item.splice(j, 1)
          })
        })
       
        // 给这个数组中的对象添加一个值
        let homes=[]
        // data.types.map((item, index) => {
        //   array.push(
        //     Object.assign({}, item, { img: 'str' })
        //   )
        // });
      
        data.types[0].img ="/assets/image/home/home.png"
        console.log(data.types[0])

        // 在把对象变成数组的形式
        data.types[1].img ="/assets/image/home/homeo.png"
        data.types[2].img = "/assets/image/home/homet.png"
        data.types[3].img = "/assets/image/home/homes.png"
        data.types[4].img = "/assets/image/home/homef.png"
        console.log(data.types)
        this.setData({
          home: data
        })
        let i = 0;
        let time = setInterval(() => {
          if (i == data.notice.length){
            i = 0;
          }
          that.setData({
            noticeNum: i * 56
          })
          i++;
        }, 2000)
      }).catch((err) => {
        wx.showToast({
          title: String(err),
          icon: 'none',
          duration: 2000
        })
      })
    },
    goMore(e) {
      let that = this;
      let index = e.currentTarget.dataset.id;
      switch(index) {
        case 0: 
          wx.navigateTo({
            url: '/pages/lineList/index?&type=work'
          })
          break;
        case 1:
          that.goBigShotMore();
          break;
        case 2:
          that.goExpertMore();
          break;
        case 3:
          that.goThemeMore();
          break;
        case 4:
          that.goScenicSpotMore();
          break;
      }
    },
    goRouteDetail(e) {
      wx.navigateTo({
        url: '/pages/routeDetail/index?id=' + e.currentTarget.dataset.id,
      })
    },
    goExpertDetail(e) {
      wx.navigateTo({
        url: '/pages/expertDetail/index?id=' + e.currentTarget.dataset.id
      })
    },
    goNoticeList(e) {
      wx.navigateTo({
        url: '/pages/noticeList/index'
      })
    },
    goBigShotMore() {
      wx.navigateTo({
        url: '/pages/bigShot/index',
      })
    },
    goExpertMore() {
      wx.navigateTo({
        url: '/pages/expertList/index',
      })
    }, 
    goThemeMore() {
      wx.navigateTo({
        url: '/pages/theme/index',
      })
    },
    goScenicSpotMore() {
      wx.navigateTo({
        url: '/pages/spots/index',
      })
    },
    goWeb(e) {
      console.log(e)
      wx.navigateTo({
        url: '/pages/web/index?src=' + e.currentTarget.dataset.src,
      })
    },
    goLineData (e) {
      wx.navigateTo({
        url: '/pages/lineList/index?id=' + e.currentTarget.dataset.id + '&type=' + e.currentTarget.dataset.type
      })
    }
  },

})